//
//  EditViewController.m
//  BigToBig
//
//  Created by 毛丽媛 on 16/7/26.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "EditViewController.h"

@interface EditViewController ()<UITextFieldDelegate>
{
    UITextField *addWord;
}

@end

@implementation EditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = self.titleName;
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    
    self.navigationController.navigationBar.translucent = NO;
    
    addWord = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, kScreenWidth - 40, 30)];
    addWord.delegate = self;
    [self.view addSubview:addWord];
    
    
    UITextField *line = [[UITextField alloc] initWithFrame:CGRectMake(15, addWord.maxY + 10, kScreenWidth - 30, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:line];
    
    UILabel *promptInfo = [[UILabel alloc] initWithFrame:CGRectMake(20,line.maxY + 5, kScreenWidth - 40, 25)];
    promptInfo.textColor = [UIColor lightGrayColor];
    promptInfo.text = self.promptInfo;
    [self.view addSubview:promptInfo];
}

#pragma mark 导航栏添加左右button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 20, 44);
    [backBtn addTarget:self action:@selector(backController) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    BackButton *saveBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 44);
    [saveBtn addTarget:self action:@selector(SaveMessage) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}
#pragma mark 保存
- (void)SaveMessage{
    [self.navigationController popViewControllerAnimated:YES];
    //调用block
    self.block(addWord.text);
}

#pragma mark 返回
- (void)backController{
    
    [self.navigationController popViewControllerAnimated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
